package com.yang.news.web.controller;

import com.google.common.collect.Lists;
import com.huaban.analysis.jieba.JiebaSegmenter;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * 分词器测试
 * @author Billyang
 * @date 2024/12/11 17:54
 */
public class WordCloudTest {
    public static void main(String[] args) {
        List<String> titleList = Lists.newArrayList(
                "《花100块做个摸鱼小网站! 》第七篇—谁访问了我们的网站？",
                "《花100块做个摸鱼小网站! 》第六篇—将小网站部署到云服务器上",
                "《花100块做个摸鱼小网站! 》第五篇—通过xxl-job定时获取热搜数据",
                "《花100块做个摸鱼小网站! 》第四篇—前端应用搭建和完成第一个热搜组件",
                "《花100块做个摸鱼小网站! 》第三篇—热搜表结构设计和热搜数据存储",
                "《花100块做个摸鱼小网站! 》第二篇—后端应用搭建和完成第一个爬虫",
                "《花100块做个摸鱼小网站! 》第一篇—买云服务器和初始化环境",
                "《花100块做个摸鱼小网站! · 序》灵感来源");
        JiebaSegmenter segmenter = new JiebaSegmenter();
        Map<String, Integer> wordCount = new HashMap<>();
        Iterator<String> var4 = titleList.iterator();

        while (var4.hasNext()) {
            String title = var4.next();
            List<String> words = segmenter.sentenceProcess(title.trim());
            Iterator<String> var7 = words.iterator();

            while (var7.hasNext()) {
                String word = var7.next();
                wordCount.put(word, wordCount.getOrDefault(word, 0) + 1);
            }
        }
        wordCount.forEach((word, count) -> {
            System.out.println("word->" + word + ";count->" + count);
        });
    }
}
